package com.work.csms.service;

import com.work.csms.dao.Notice;
import com.work.csms.mapper.NoticeMapper;
import com.work.csms.pojo.PageParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class NoticeService {

    @Autowired(required = false)
    private NoticeMapper noticeMapper;

    public Map<String, Object> page(Notice notice, PageParam pageParam) throws Exception {
        Map<String, Object> result = new HashMap<>();
        Integer count = noticeMapper.count(notice.getTitle());
        List<Notice> page = noticeMapper.page(notice.getTitle(), (pageParam.getPageNo() - 1) * pageParam.getPageSize(), pageParam.getPageSize());
        result.put("count", count);
        result.put("pageSize", pageParam.getPageSize());
        result.put("pageNo", pageParam.getPageNo());
        result.put("data", page);
        return result;
    }

    public List<Notice> list(Notice notice) throws Exception {
        return noticeMapper.list(notice);
    }

    public Notice getNoticeById(Integer id) throws Exception {
        return noticeMapper.getNoticeById(id);
    }

    public void save(Notice notice) throws Exception {
        noticeMapper.save(notice);
    }

    public void update(Notice notice) throws Exception {
        noticeMapper.update(notice);
    }

    public void deleted(Integer id) throws Exception {
        noticeMapper.deleted(id);
    }

}
